package promote.brozen.spring.boot.configprop;

import lombok.Data;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Configuration;

/**
 * @author Brozen
 * @date 2020/8/26 5:31 PM
 * @email brozen@qq.com
 */
@SpringBootApplication(scanBasePackageClasses = {ConfigurationPropertiesTest.class})
public class ConfigurationPropertiesTest {

    public static void main(String[] args) {
        new SpringApplicationBuilder()
                .web(WebApplicationType.NONE)
                .sources(ConfigurationPropertiesTest.class)
                .build()
                .run(args);
    }

    @Configuration
    @EnableConfigurationProperties({Config.class})
    public static class Init implements InitializingBean {

        @Autowired
        private Config config;

        @Override
        public void afterPropertiesSet() throws Exception {
            System.out.println(config.toString());
        }
    }

    @Data
    @ConfigurationProperties("brozen.cptest")
    public static class Config {

        private String common;

        private String withCamel;

        private String withUnderLine;

        private String withCenterLine;

    }

}
